package com.amigo.online.provider.manager.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.amigo.online.provider.manager.mapper.MerchantAdvTblMapper;
import com.amigo.online.provider.manager.model.entity.MerchantAdvTbl;
import com.amigo.online.provider.manager.service.MerchantAdvTblService;
import com.amigo.online.provider.manager.util.param.dto.RedisKey;

@Service
public class MerchantAdvTblServiceImpl implements MerchantAdvTblService {

    @SuppressWarnings("rawtypes")
    @Autowired
    RedisTemplate redisTemplate;

    @Resource
    private MerchantAdvTblMapper merchantAdvTblMapper;

    @Override
    public List<MerchantAdvTbl> selectMerchantAdvTblList(MerchantAdvTbl merchantAdvTbl) {

        return merchantAdvTblMapper.selectMerchantAdvTblList(merchantAdvTbl);
    }

    @SuppressWarnings("unchecked")
    @Override
    public Boolean updateMerchantAdvTbl(MerchantAdvTbl merchantAdvTbl) {
        merchantAdvTbl.setUpdatedTime(System.currentTimeMillis() / 1000);
        redisTemplate.delete(RedisKey.MERCHANT_ADV_KEY);
        return merchantAdvTblMapper.updateMerchantAdvTbl(merchantAdvTbl) > 0;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Boolean deleteMerchantAdvTbl(MerchantAdvTbl merchantAdvTbl) {
        merchantAdvTbl.setDeleted(1);
        merchantAdvTbl.setDeletedTime(System.currentTimeMillis() / 1000);
        redisTemplate.delete(RedisKey.MERCHANT_ADV_KEY);
        return merchantAdvTblMapper.updateMerchantAdvTbl(merchantAdvTbl) > 0;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Boolean insertMerchantAdvTbl(MerchantAdvTbl merchantAdvTbl) {
        merchantAdvTbl.setDeleted(0);
        merchantAdvTbl.setCreatedTime(System.currentTimeMillis() / 1000);

        redisTemplate.delete(RedisKey.MERCHANT_ADV_KEY);
        return merchantAdvTblMapper.insert(merchantAdvTbl) > 0;
    }

}
